
class Dog{
    public String name;
    public int age;

    public void eat(){
        System.out.println(name+"吃狗粮");
    }
}

public class Test2 {

    public void test(){
        System.out.println("111111");
    }

    public static void main(String[] args) {
        Test2 test2=new Test2();
        test2.test();
    }

    //通过对象的引用，可以得到对象的成员变量和方法
    public static void main1(String[] args) {
        Dog dog=new Dog();//对象的引用
        dog.name="小黑";
        dog.age=12;//对象的成员变量
        dog.eat();//对象的方法
        System.out.println(dog.name);
        System.out.println(dog.age);

        System.out.println("=======================");

        //可以通过关键字new实例化多个对象
        Dog dog2=new Dog();
        dog2.name="小黄";
        dog2.age=22;
        dog2.eat();
        System.out.println(dog2.name);
        System.out.println(dog2.age);

    }
}
